<!DOCTYPE html>
<html xmlns:v-on="http://www.w3.org/1999/xhtml" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <script src="https://unpkg.com/vue/dist/vue.js"></script>

    <style type="text/css">
    </style>

    <title>hello</title>
</head>
<body>
<h1 id="h01"></h1>
<form id="myform">
    <label>xxx</label><input value="sss1"/><input value="sss3"/>
</form>
<div id="app">
    <span>1</span><div class="xxx">{{ message }}1</div>
    <span>2</span><div v-text="message">2</div>
    <span>3</span><div v-html="message">3</div>
    <span>4</span><div v-once>{{ message }}4</div>
</div>
<div id="app-2">
  <span v-bind:title="message">
    鼠标悬停几秒钟查看此处动态绑定的提示信息！
  </span>
</div>
<button onclick="seen()">switch seen</button>
<div id="app-3">
    <p v-if="seen">现在你看到我了(del tag)</p>
    <p v-show="seen">v-show(display:none)</p>
</div>
<div id="app-4">
    <ol>
        <li v-for="todo in todos">
            {{ todo.text }}
        </li>
    </ol>
</div>
<div id="app-5">
    <p>{{ message }}</p>
    <button v-on:click="reverseMessage">逆转消息</button>
    <!--单向观察-->
    <input v-on:keyup="handleKeyup">
    <!--双向绑定-->
    <input v-model="message">
    <select v-model="selectedOption">
        <option value="0">000</option>
        <option value="1">111</option>
        <option value="2">222</option>
    </select>

</div>
<div id="app-6">
    <p>{{ message }}</p>
    <!--<input :value="message" @input="message = $event.target.value">-->
    <!--v-model效果同上-->
    <input v-model="message">
</div>
<div id="app-7">
    <input v-model="text">
    <button @click="insertData">Add</button>
    <ol>
        <!-- 现在我们为每个todo-item提供待办项对象    -->
        <!-- 待办项对象是变量，即其内容可以是动态的 -->
        <todo-item v-for="(item, idx) in groceryList" :delete-row="deleteRow" :idx="idx" :todo="item" @del-item="deleteRow"></todo-item>
    </ol>
    <p>共{{ listSize }}行</p>
</div>
<div id="app-8">
    <tw-date-input></tw-date-input>
</div>
<template id="tw-date-input-template">
    <div>
        <input type="number" v-model="year">
        <input type="number" v-model="month">
        <input type="number" v-model="day">
    </div>
</template>
<script>


    var app = new Vue({
        el: '#app',
        data: {
            message: 'Hello Vue!'
        }
    });

    var app2 = new Vue({
        el: '#app-2',
        data: {
            message: '页面加载于 ' + new Date()
        }
    });

    var app3 = new Vue({
        el: '#app-3',
        data: {
            seen: false
        }
    });
    var app4 = new Vue({
        el: '#app-4',
        data: {
            todos: [
                { text: '学习 JavaScript' },
                { text: '学习 Vue' },
                { text: '整个牛项目' }
            ]
        }
    });
    var app5 = new Vue({
        el: '#app-5',
        data: {
            message: 'Hello Vue.js!',
            selectedOption: "0"
        },
        methods: {
            reverseMessage: function () {
                this.message = this.message.split('').reverse().join('');
            },
            handleKeyup: function (e) {
                this.message = e.target.value;
            }
        }
    });
    var app6 = new Vue({
        el: '#app-6',
        data: {
            message: 'Hello Vue!'
        },
        beforeCreate: function () {
            // `this` 指向 vm 实例
            console.log('beforeCreate message is: ' + this.message)
        },
        created: function () {
            // `this` 指向 vm 实例
            console.log('message is: ' + this.message)
        }
    });
    Vue.component('todo-item', {
//        props: ['todo', 'idx', 'deleteRow'],
        props: {
            todo: {
                type: Object
            },
            idx: {
                type: Number
            },
            deleteRow: {
                type: Function
            }
        },
//        template: '<li>{{ todo.text }}<button @click="deleteRow(idx)">X</button></li>',//不传处理方法到子组件，而是通过下面的方法发送自定义事件，让父组件接收事件
        template: '<li>{{ todo.text }}<button @click="delItem()">X</button></li>',
        methods: {
            delItem: function () {
                this.$emit('del-item', this.idx);
            }
        }
    });
    var app7 = new Vue({
        el: '#app-7',
        data: {
            text: "",
            groceryList: [
                { text: '蔬菜' },
                { text: '奶酪' },
                { text: '随便其他什么人吃的东西' }
            ]
        },
        computed: {
            listSize: function () {
                return this.groceryList.length;
            }
        },
        methods:{
            insertData: function () {
                if (this.text.length == 0) {
                    return;
                }
                this.groceryList.push({text: this.text});
                this.text = "";
            },
            deleteRow: function (idx) {
                this.groceryList.splice(idx, 1);
            }
        }
    });


    Vue.component('tw-date-input', {
        template: '#tw-date-input-template',
        props: {
            value: {
                type: String,
                default: ""
            }
        },
        data: function () {
            return {
                year:"",
                month:"",
                day:"",
                d:null
            }
        }
    });

    var app8 = new Vue({
        el: '#app-8'
    });
    $(function () {
//            $("#h01").attr("style", "color:red").html("Hello jQuery");
        $("#h01").css("color", "red").html("Hello jQuery1");
        $('#myform > input:first').val("my");
        console.info($("#h01").text());
        console.info($("#h01").html());



    });



    function seen() {
        app.message="<br/>";
        app3.seen=!app3.seen;
    }
</script>
</body>
</html>